import Vue from 'vue'
export default {
    namespaced: true,
    state() {
        return {
            'collectionList': [
                {
                    'gid': 120054,
                    'img': "https://img2.epetbar.com/common/upload/commonfile/2020/02/26/162433_849923.jpg",
                    'title': "加拿大原装进口 爱肯拿Acana 无谷鸭肉巴特利梨配方全犬粮 2kg",
                    'subtitle': "加拿大渴望狗粮同厂出品原装进口",
                    'price': 99.00,
                    'format': '2kg',
                    'isCheck': true,
                }
            ],
            'nowCheckoutList': [
                {
                    'gid': 120054,
                    'img': "https://img2.epetbar.com/common/upload/commonfile/2020/02/26/162433_849923.jpg",
                    'title': "加拿大原装进口 爱肯拿Acana 无谷鸭肉巴特利梨配方全犬粮 2kg",
                    'subtitle': "加拿大渴望狗粮同厂出品原装进口",
                    'price': 99.00,
                    'format': '2kg',
                }
            ]
        }
    },
    mutations: {
        addCollection(state, obj) {
            let { collectionList } = state
            let Len = collectionList.length
            for (let i = 0; i < Len; i++) {
                if (collectionList[i].gid == obj.gid) { //如果有相同gid码,则删除收藏商品,表示取消收藏
                    // console.log('1111',i);
                    state.collectionList.splice(i, 1)
                    return
                }
            }
            Vue.set(obj, 'isCheck', true)
            state.collectionList.push(obj)
            // console.log(state.collectionList)
        },
        nowCheckout(state, obj) {
            Vue.set(obj, 'isCheck', true)
            state.nowCheckoutList.push(obj)
        }
    }
}